home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / graphics / gif2rpc / source / 16bpp_48bi / c / sierra2_4a < prev    next >
Encoding:
Text File  |  1995-10-16  |  3.5 KB  |  118 lines

  1. /* sierra2_4a.c
  2.  * AUTHOR:      Cy Booker, cy@cheepnis.demon.co.uk
  3.  * LICENSE:     FreeWare, Copyright (c) 1995 Cy Booker
  4.  *
  5.  * filter:              *  2
  6.  *                   1  1               (1/4)
  7.  */
  8.  
  9. #include "internal.h"
  10.  
  11. #include <assert.h>
  12. #include <string.h>             /* memset() */
  13. #include <stdlib.h>             /* calloc() */
  14.  
  15. #include "OS:hourglass.h"
  16. #include "OS:macros.h"
  17.  
  18.  
  19.  
  20. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  21.  */
  22.  
  23. extern bool process_gif_16bpp_sierra2_4a_48bit(
  24.                 const process_gif       *p) {
  25.   byte                  *rove;
  26.   int                   width, height;
  27.   int                   x, y;
  28.   const os_colour       *palette;
  29.   int                   line_length;
  30.   int                   *buffer, *this_row, *next_row;
  31.   int                   buffer_width;
  32.   int                   red, grn, blu;
  33.   bits                  t;
  34.   int                   error_red, error_grn, error_blu;
  35.   int                   temp_red, temp_grn, temp_blu;
  36.   rgbtupleout           error;
  37.   rgbtupleout_fn        fn;
  38.  
  39.   assert(p);
  40.   assert(p->pixel_width > 0);
  41.   assert(p->pixel_height > 0);
  42.   assert(p->in_palette.colours);
  43.   assert(p->fn);
  44.  
  45.   /*
  46.    * sierra2_4a requires storing error info for one pixel to left
  47.    * so we will just allocate one extra column for each row and not do any edge checks
  48.    * each entry is stored as {r*SCALE, g*SCALE, b*SCALE}
  49.    */
  50.   buffer_width = (1 + p->pixel_width) * 3;
  51.   buffer = calloc(1, sizeof(*buffer) * (buffer_width * 2));
  52.   if (!buffer) {
  53.     /*
  54.      * oh dear
  55.      */
  56.     return TRUE;
  57.   }
  58.  
  59.   /*
  60.    * not we pre-load values from the process_gif array
  61.    * because it considerably helps the compiler produce better code
  62.    */
  63.   rove = p->buffer;
  64.   width = p->pixel_width;
  65.   height = p->pixel_height;
  66.   palette = p->in_palette.colours;
  67.   line_length = p->line_length;
  68.   fn = p->fn;
  69.   for (y= height; (y > 0); y--) {
  70.     if ((y & 7) == 0) {
  71.       xhourglass_percentage((y * 100) / height);
  72.     }
  73.     this_row = buffer + (buffer_width * ((y + 2) % 2)) + 1*3;
  74.     next_row = buffer + (buffer_width * ((y + 1) % 2)) + 0*3;
  75.     /* bottom row has no errors */
  76.     memset(next_row, 0, sizeof(*next_row) * (buffer_width - 1*3));
  77.     error_red = error_grn = error_blu = 0;                      /* error along this row */
  78.     /*
  79.      * note that just because we are actually scanning/outputting right to left
  80.      * doesn't matter as far as sierra2_4a is concerned
  81.      * although it might help if we could ``snake''
  82.      */
  83.     for (x= width - 1; (x >= 0); x--) {
  84.       INPUT;
  85.  
  86.       red += *this_row++;                               /* add in errors from all rows */
  87.       grn += *this_row++;
  88.       blu += *this_row++;
  89.  
  90.       red += error_red;                                 /* add in errors from this row */
  91.       grn += error_grn;
  92.       blu += error_blu;
  93.  
  94.       PROCESS;
  95.  
  96.       temp_red = red / 4;                               /* diffuse pixel `below left' */
  97.       temp_grn = grn / 4;
  98.       temp_blu = blu / 4;
  99.       *next_row += temp_red; next_row++;
  100.       *next_row += temp_grn; next_row++;
  101.       *next_row += temp_blu; next_row++;
  102.  
  103.       next_row[0] += temp_red;                          /* diffuse pixel `below' */
  104.       next_row[1] += temp_grn;
  105.       next_row[2] += temp_blu;
  106.  
  107.       error_red = red - (temp_red * 2);                 /* diffuse pixel to `right' */
  108.       error_grn = grn - (temp_grn * 2);
  109.       error_blu = blu - (temp_blu * 2);
  110.     }
  111.     rove += line_length;
  112.   }
  113.   free(buffer);
  114.   return FALSE;
  115. }
  116.  
  117.  
  118.